﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Concurrent;

namespace FrameworkLib
{
    public class GlobalConfiguration
    {
        private ConcurrentDictionary<string, object> m_items = null;

        public GlobalConfiguration()
        {
            m_items = new ConcurrentDictionary<string, object>();
        }

        public bool Add(string key, object T)
        {
            return this.m_items.TryAdd(key, T);
        }

        public object Get(string key)
        {
            object retValue = null;

            this.m_items.TryGetValue(key, out retValue);

            return retValue;
        }

        public bool Delete(string key)
        {
            object retValue = null;

            return this.m_items.TryRemove(key, out retValue);
        }

        public bool Update(string key, object T)
        {
            bool retValue = false;

            object oldValue = Get(key);
            object newValue = this.m_items.AddOrUpdate(key, T, (s, O) => O = T);

            retValue = (oldValue != newValue);

            return retValue;
        }
    }
}
